<?php
defined('IN_TS') or die('Access Denied.');

//核心配置文件 $TS_CF 系统配置变量
$TS_CF = include THINKROOT.'/thinksaas/config.php';

// 如果是调试模式，打开警告输出
if ($TS_CF['debug']) {
	if( substr(PHP_VERSION, 0, 3) == "5.3" ){
		error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
	}else{
		error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
	}
} else {
	error_reporting(0);
}

@set_magic_quotes_runtime(0);

//ini_set("memory_limit","120M");

ini_set('display_errors', 'on');   //正式环境关闭错误输出

set_time_limit (0);

ini_set('session.cookie_path', '/');

//ini_set('session.save_path', THINKROOT.'/cache/sessions');

//加载基础函数
include 'tsFunction.php';

//开始计算程序执行时间
$time_start = getmicrotime();

//处理fileurl
if($TS_CF['fileurl']['url']){
	if($_SERVER['HTTP_HOST']==$TS_CF['fileurl']['url']){
		echo '404 page';exit;
	}
}

//数据库存储SESSION  还有点问题，暂时不要开启
if($TS_CF['session']){
	include 'tsSession.php';
	ini_set('session.save_handler', 'user');
	session_set_save_handler(
		array('tsSession', 'open'),
		array('tsSession', 'close'),
		array('tsSession', 'read'),
		array('tsSession', 'write'),
		array('tsSession', 'destroy'),
		array('tsSession', 'gc')
	);
}

session_start();

$_SESSION['province']=array(
	'pid'	=>	1,
	'pname'	=>	'上海',
);

//启动Memcache
if($TS_CF['memcache'] && extension_loaded('memcache')){
	Memcache::connect($TS_CF['memcache']['host'], $TS_CF['memcache']['port']);
}

//加密用户操作
if(!isset($_SESSION['token'])){
	$_SESSION['token'] = sha1(uniqid(mt_rand(),TRUE));
}

if($_REQUEST['token']){
	if(tsFilter($_REQUEST['token']) != $_SESSION['token']) {
		mt_location('页面已失效，请重新登录！');
	}
}

//前台用户基本数据,$TS_USER数组
$TS_USER = array(
	'user'		=> isset($_SESSION['tsuser']) ? $_SESSION['tsuser'] : '',
	'admin'		=> isset($_SESSION['tsadmin']) ? $_SESSION['tsadmin'] : '',
);

//记录日志
if($TS_CF['logs']){
	//打印用户日志记录
	userlog($_POST,intval($TS_USER['user']['userid']));
	userlog($_GET,intval($TS_USER['user']['userid']));
}

//处理html编码
header('Content-Type: text/html; charset=UTF-8');


//数据库配置文件
include THINKDATA.'/config.inc.php';

//连接数据库
include THINKSAAS.'/sql/'.$TS_DB['sql'].'.php';
$db = new MySql($TS_DB);

//加载APP数据库操作类并建立对象
include THINKSAAS.'/tsApp.php';


//判断magic_quotes_gpc状态
if(!get_magic_quotes_gpc()) {
	$_GET = tsgpc ( $_GET );
	$_POST = tsgpc ( $_POST );
	$_COOKIE = tsgpc ( $_COOKIE );
	//$_FILES = tsgpc ( $_FILES );
}
//$_SERVER = tsgpc ( $_SERVER );

$mt_userid=isset($_SESSION['tsuser']['userid']) ? $_SESSION['tsuser']['userid'] : 0;
//360安全过滤
if(is_file($_SERVER['DOCUMENT_ROOT'].'/360safe/360webscan.php')){
    require_once($_SERVER['DOCUMENT_ROOT'].'/360safe/360webscan.php');
}
// include THINKROOT.'/app/home/class.home.php';
$xht=new tsApp($db);